from django.db import models

# Create your models here.
class Author(models.Model):

    name = models.CharField('姓名', max_length=11)

class Book(models.Model):

    title = models.CharField('书名', max_length=11)
    authors = models.ManyToManyField(Author)

# >>> from mtm.models import *
# >>> a1 = Author.objects.create(name='guolaoshi')
# >>> b1 = a1.book_set.create(title='python')
# mysql> select * from mtm_book_authors;
# +----+---------+-----------+
# | id | book_id | author_id |
# +----+---------+-----------+
# |  1 |       1 |         1 |
# +----+---------+-----------+
# 1 row in set (0.00 sec)
# >>> from mtm.models import *
# >>> a1 = Author.objects.create(name='guolaoshi')
# >>> b1 = a1.book_set.create(title='python')
# >>> a2 = Author.objects.create(name='wanglaoshi')
# >>> a2.book_set.add(b1)
# mysql> select * from mtm_book_authors;
# +----+---------+-----------+
# | id | book_id | author_id |
# +----+---------+-----------+
# |  1 |       1 |         1 |
# |  2 |       1 |         2 |
# +----+---------+-----------+
# 2 rows in set (0.00 sec)
